# -*- coding: utf-8 -*-
"""
Created on Mon Sep 20 14:46:56 2021

@author: 刘长奇-2019300677
"""

               
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon   
  
def fun(x):
    return  3*(x**2)+10

x=np.linspace(-5,5,50)
y=fun(x)

#开始绘制二次函数曲线图：

fig,ax=plt.subplots(figsize=(7,5))
plt.plot(x,y,label='3*x^2+10')
plt.legend(loc='upper right')
plt.title('3*x^2+10')
plt.xticks(np.linspace(-6,7,14))
plt.yticks(np.linspace(5,100,12))
plt.xlabel('x')
plt.ylabel('y')

#开始绘制小梯形区间：

for i in range(0,49):
    a=x[i]
    b=x[i+1]
    Ix=np.linspace(a,b)
    Iy=fun(Ix)
    verts=[(a,0)]+list(zip(Ix,Iy))+[(b,0)]
    poly=Polygon(verts,facecolor='0.95',edgecolor='0')   #绘制曲线阴影部分
    ax.add_patch(poly)  
plt.show()     


 


